package com.liqi.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.liqi.common.utils.SecurityUtils;
import com.liqi.info.domain.TInfoFwzx;
import com.liqi.info.service.ITInfoFwzxService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.liqi.common.annotation.Log;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.domain.AjaxResult;
import com.liqi.common.enums.BusinessType;
import com.liqi.common.utils.poi.ExcelUtil;
import com.liqi.common.core.page.TableDataInfo;

/**
 * 服务之星Controller
 * 
 * @author ruoyi
 * @date 2022-11-09
 */
@RestController
@RequestMapping("/info/fwzx")
public class TInfoFwzxController extends BaseController
{
    @Autowired
    private ITInfoFwzxService tInfoFwzxService;

    /**
     * 查询服务之星列表集合
     */
    @PreAuthorize("@ss.hasPermi('info:fwzx:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInfoFwzx tInfoFwzx)
    {
        startPage();
        List<TInfoFwzx> list = tInfoFwzxService.selectTInfoFwzxList(tInfoFwzx);
        return getDataTable(list);
    }

    /**
     * 导出服务之星列表
     */
    @PreAuthorize("@ss.hasPermi('info:fwzx:export')")
    @Log(title = "服务之星", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInfoFwzx tInfoFwzx)
    {
        List<TInfoFwzx> list = tInfoFwzxService.selectTInfoFwzxList(tInfoFwzx);
        ExcelUtil<TInfoFwzx> util = new ExcelUtil<TInfoFwzx>(TInfoFwzx.class);
        util.exportExcel(response, list, "服务之星数据");
    }

    /**
     * 获取服务之星详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:fwzx:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tInfoFwzxService.selectTInfoFwzxById(id));
    }

    /**
     * 新增服务之星
     */
    @PreAuthorize("@ss.hasPermi('info:fwzx:add')")
    @Log(title = "服务之星", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInfoFwzx tInfoFwzx)
    {
        Long userId = SecurityUtils.getUserId();
        Long deptId = SecurityUtils.getDeptId();
        tInfoFwzx.setCreateUserId(String.valueOf(userId));
        tInfoFwzx.setDeptId(String.valueOf(deptId));
        tInfoFwzx.setStatus(0);
        tInfoFwzx.setTYear("0");
        tInfoFwzx.setTMonth("0");
        return toAjax(tInfoFwzxService.insertTInfoFwzx(tInfoFwzx));
    }

    /**
     * 修改服务之星
     */
    @PreAuthorize("@ss.hasPermi('info:fwzx:edit')")
    @Log(title = "服务之星", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInfoFwzx tInfoFwzx)
    {
        return toAjax(tInfoFwzxService.updateTInfoFwzx(tInfoFwzx));
    }

    /**
     * 删除服务之星
     */
    @PreAuthorize("@ss.hasPermi('info:fwzx:remove')")
    @Log(title = "服务之星", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInfoFwzxService.deleteTInfoFwzxByIds(ids));
    }
}
